<?php

/***

LZRoster: A roster for World of Warcraft.
Copyright (C) 2007  Emmanuel Cron

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.

***/

class Revision
{
	static private $instance;
	
	private $f_installed_revision;
	private $current_revision;
	private $installed_revision;
	
	private function __construct()
	{
		// Modify this line to update the Revision: ko
		$this->current_revision = substr("\$Revision: 403 $", 11, strlen("\$Revision: 403 $")-13);
		
		$this->f_installed_revision = dirname(__FILE__)."/../class.data/Revision.installed_revision.serialize";
		
		if ( file_exists($this->f_installed_revision) )
		{
			$this->installed_revision = file_get_contents($this->f_installed_revision);
		}
		else
		{
			if ( file_put_contents($this->f_installed_revision, "0") == FALSE )
			{
				trigger_error("Could not write in class.data folder. Please check that you have the rights to do so.", E_USER_ERROR);
			}
			
			$this->installed_revision = 0;
		}
	}
	
	static function GetInstance()
	{
		if ( empty(self::$instance) )
		{
			self::$instance = new Revision();
		}
		
		return self::$instance;
	}
	
	function GetCurrentRevision()
	{
		return $this->current_revision;
	}
	
	function GetInstalledRevision()
	{
		return $this->installed_revision;
	}
	
	function NeedsUpgrade()
	{
		if ($this->installed_revision < $this->current_revision)
		{
			return true;
		}
		else
		{
			return false;
		}
	}
	
	function UpdateInstalledRevision()
	{
		if ( file_put_contents($this->f_installed_revision, $this->current_revision) == FALSE)
		{
			return false;
		}
		else
		{
			return true;
		}
	}
}

?>